package exam;

import java.util.*;

/**
 * Tests the answer to the fourth sample question.
 * The text of the question is as follows:
 * "3: Write a method that takes a List<Integer> as a parameter and swaps the values 
 * at the indices given.  If either of the index values are out of the range of the List,
 * then do not change the List."
 * 
 * @author Branden Ogata
 *
 */

public class TestSampleA03 extends Tester
{
  public static void main(String[] args)
  {
    final double points = getPoints(args);
    
    SampleA03 question = new SampleA03();
    
    List<Integer> values = makeList();
    
    // Normal swap
    question.swap(values, 1, 2);
    System.out.println(test(Category.EQUALS, "swap([0, 1, 2, 4], 1, 2) should have 2 at index 1", 
                            2, values.get(1), percentageToPoints(0.16, points)));
    System.out.println(test(Category.EQUALS, "swap([0, 1, 2, 4], 1, 2) should have 1 at index 2", 
                            1, (int) values.get(2), percentageToPoints(0.16, points)));
    
    // Swap at ends of the array
    values = makeList();
    question.swap(values, 0, 3);
    System.out.println(test(Category.EQUALS, "swap([0, 1, 2, 4], 0, 3) should have 4 at index 0", 
                            4, (int) values.get(0), percentageToPoints(0.16, points)));
    System.out.println(test(Category.EQUALS, "swap([0, 1, 2, 4], 0, 3) should have 0 at index 3", 
                            0, (int) values.get(3), percentageToPoints(0.16, points)));

    
    // Swap with self
    values = makeList();
    question.swap(values, 1, 1);
    System.out.println(test(Category.EQUALS, "swap([0, 1, 2, 4], 1, 1) should have 1 at index 1", 
                            1, (int) values.get(1), percentageToPoints(0.16, points)));
    
    // Invalid first index
    values = makeList();
    question.swap(values, -1, 1);
    System.out.println(test(Category.EQUALS, "swap([0, 1, 2, 4], -1, 1) should be unchanged", 
                            makeList(), values, percentageToPoints(0.10, points)));
    
    // Invalid second index
    values = makeList();
    question.swap(values, 2, 5);
    System.out.println(test(Category.EQUALS, "swap([0, 1, 2, 4], 2, 5) should be unchanged", 
                            makeList(), values, percentageToPoints(0.10, points)));

    System.out.format("[%.2f/%.2f]%n", getTotalPoints(), points);
  }
  
  /**
   * Sets up a List<Integer> with values 0, 1, 2, 4.
   * 
   * @return list A List<Integer> containing the values 0, 1, 2, and 4.
   * 
   */
  
  private static List<Integer> makeList()
  {
    List<Integer> list = new ArrayList<Integer>();
    list.add(0);
    list.add(1);
    list.add(2);
    list.add(4);
    
    return list;
  }
}
